
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  
<!-- Mirrored from werkzeug.palletsprojects.com/en/1.0.x/http/ by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 15 Sep 2020 06:37:09 GMT -->
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>HTTP Utilities &#8212; Werkzeug Documentation (1.0.x)</title>
    <link rel="stylesheet" href="../_static/werkzeug.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../../../assets.readthedocs.org/static/css/badge_only.css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script async="async" type="text/javascript" src="../../../../assets.readthedocs.org/static/javascript/readthedocs-doc-embed.js"></script>
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
    <link rel="index" title="Index" href="../genindex/index.html" />
    <link rel="search" title="Search" href="../search/index.html" />
    <link rel="next" title="Data Structures" href="../datastructures/index.html" />
    <link rel="prev" title="Filesystem Utilities" href="../filesystem/index.html" />
    <link rel="canonical" href="index.html">
  <script>DOCUMENTATION_OPTIONS.URL_ROOT = '../index.html';</script>
   
  
<!-- RTD Extra Head -->

<!-- 
Always link to the latest version, as canonical.
http://docs.readthedocs.org/en/latest/canonical.html
-->
<link rel="canonical" href="index.html" />

<link rel="stylesheet" href="../../../../assets.readthedocs.org/static/css/readthedocs-doc-embed.css" type="text/css" />

<script type="text/javascript" src="../_static/readthedocs-data.js"></script>

<!-- Add page-specific data, which must exist in the page js, not global -->
<script type="text/javascript">
READTHEDOCS_DATA['page'] = "http"
READTHEDOCS_DATA['source_suffix'] = ".rst"
</script>

<script type="text/javascript" src="../../../../assets.readthedocs.org/static/javascript/readthedocs-analytics.js" async="async"></script>

<!-- end RTD <extrahead> -->
</head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex/index.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex/index.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../datastructures/index.html" title="Data Structures"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="../filesystem/index.html" title="Filesystem Utilities"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">Werkzeug Documentation (1.0.x)</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-werkzeug.http">
<span id="http-utilities"></span><h1>HTTP Utilities<a class="headerlink" href="#module-werkzeug.http" title="Permalink to this headline">¶</a></h1>
<p>Werkzeug provides a couple of functions to parse and generate HTTP headers
that are useful when implementing WSGI middlewares or whenever you are
operating on a lower level layer.  All this functionality is also exposed
from request and response objects.</p>
<div class="section" id="date-functions">
<h2>Date Functions<a class="headerlink" href="#date-functions" title="Permalink to this headline">¶</a></h2>
<p>The following functions simplify working with times in an HTTP context.
Werkzeug uses offset-naive <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> objects internally
that store the time in UTC.  If you’re working with timezones in your
application make sure to replace the tzinfo attribute with a UTC timezone
information before processing the values.</p>
<dl class="function">
<dt id="werkzeug.http.cookie_date">
<code class="descclassname">werkzeug.http.</code><code class="descname">cookie_date</code><span class="sig-paren">(</span><em>expires=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.cookie_date" title="Permalink to this definition">¶</a></dt>
<dd><p>Formats the time to ensure compatibility with Netscape’s cookie
standard.</p>
<p>Accepts a floating point number expressed in seconds since the epoch in, a
datetime object or a timetuple.  All times in UTC.  The <a class="reference internal" href="#werkzeug.http.parse_date" title="werkzeug.http.parse_date"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_date()</span></code></a>
function can be used to parse such a date.</p>
<p>Outputs a string in the format <code class="docutils literal notranslate"><span class="pre">Wdy,</span> <span class="pre">DD-Mon-YYYY</span> <span class="pre">HH:MM:SS</span> <span class="pre">GMT</span></code>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>expires</strong> – If provided that date is used, otherwise the current.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.http_date">
<code class="descclassname">werkzeug.http.</code><code class="descname">http_date</code><span class="sig-paren">(</span><em>timestamp=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.http_date" title="Permalink to this definition">¶</a></dt>
<dd><p>Formats the time to match the RFC1123 date format.</p>
<p>Accepts a floating point number expressed in seconds since the epoch in, a
datetime object or a timetuple.  All times in UTC.  The <a class="reference internal" href="#werkzeug.http.parse_date" title="werkzeug.http.parse_date"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_date()</span></code></a>
function can be used to parse such a date.</p>
<p>Outputs a string in the format <code class="docutils literal notranslate"><span class="pre">Wdy,</span> <span class="pre">DD</span> <span class="pre">Mon</span> <span class="pre">YYYY</span> <span class="pre">HH:MM:SS</span> <span class="pre">GMT</span></code>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>timestamp</strong> – If provided that date is used, otherwise the current.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_date">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_date</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_date" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse one of the following date formats into a datetime object:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov  6 08:49:37 1994       ; ANSI C&#39;s asctime() format
</pre></div>
</div>
<p>If parsing fails the return value is <cite>None</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> – a string with a supported date format.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a> object.</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="header-parsing">
<h2>Header Parsing<a class="headerlink" href="#header-parsing" title="Permalink to this headline">¶</a></h2>
<p>The following functions can be used to parse incoming HTTP headers.
Because Python does not provide data structures with the semantics required
by <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2616.html"><strong>RFC 2616</strong></a>, Werkzeug implements some custom data structures that are
<a class="reference internal" href="../datastructures/index.html#http-datastructures"><span class="std std-ref">documented separately</span></a>.</p>
<dl class="function">
<dt id="werkzeug.http.parse_options_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_options_header</code><span class="sig-paren">(</span><em>value</em>, <em>multiple=False</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_options_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a <code class="docutils literal notranslate"><span class="pre">Content-Type</span></code> like header into a tuple with the content
type and the options:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parse_options_header</span><span class="p">(</span><span class="s1">&#39;text/html; charset=utf8&#39;</span><span class="p">)</span>
<span class="go">(&#39;text/html&#39;, {&#39;charset&#39;: &#39;utf8&#39;})</span>
</pre></div>
</div>
<p>This should not be used to parse <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> like headers that use
a slightly different format.  For these headers use the
<a class="reference internal" href="#werkzeug.http.parse_dict_header" title="werkzeug.http.parse_dict_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_dict_header()</span></code></a> function.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.15: </span><span class="target" id="index-1"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2231.html"><strong>RFC 2231</strong></a> parameter continuations are handled.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>value</strong> – the header to parse.</li>
<li><strong>multiple</strong> – Whether try to parse and return multiple MIME types</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">(mimetype, options) or (mimetype, options, mimetype, options, …)
if multiple=True</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_set_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_set_header</code><span class="sig-paren">(</span><em>value</em>, <em>on_update=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_set_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a set-like header and return a
<a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.HeaderSet" title="werkzeug.datastructures.HeaderSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderSet</span></code></a> object:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">hs</span> <span class="o">=</span> <span class="n">parse_set_header</span><span class="p">(</span><span class="s1">&#39;token, &quot;quoted value&quot;&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The return value is an object that treats the items case-insensitively
and keeps the order of the items:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;TOKEN&#39;</span> <span class="ow">in</span> <span class="n">hs</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hs</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;quoted value&#39;</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hs</span>
<span class="go">HeaderSet([&#39;token&#39;, &#39;quoted value&#39;])</span>
</pre></div>
</div>
<p>To create a header from the <code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderSet</span></code> again, use the
<a class="reference internal" href="#werkzeug.http.dump_header" title="werkzeug.http.dump_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump_header()</span></code></a> function.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>value</strong> – a set header to be parsed.</li>
<li><strong>on_update</strong> – an optional callable that is called every time a
value on the <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.HeaderSet" title="werkzeug.datastructures.HeaderSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderSet</span></code></a>
object is changed.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.HeaderSet" title="werkzeug.datastructures.HeaderSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderSet</span></code></a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_list_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_list_header</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_list_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse lists as described by RFC 2068 Section 2.</p>
<p>In particular, parse comma-separated lists where the elements of
the list may include quoted-strings.  A quoted-string could
contain a comma.  A non-quoted string could have quotes in the
middle.  Quotes are removed automatically after parsing.</p>
<p>It basically works like <a class="reference internal" href="#werkzeug.http.parse_set_header" title="werkzeug.http.parse_set_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_set_header()</span></code></a> just that items
may appear multiple times and case sensitivity is preserved.</p>
<p>The return value is a standard <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parse_list_header</span><span class="p">(</span><span class="s1">&#39;token, &quot;quoted value&quot;&#39;</span><span class="p">)</span>
<span class="go">[&#39;token&#39;, &#39;quoted value&#39;]</span>
</pre></div>
</div>
<p>To create a header from the <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> again, use the
<a class="reference internal" href="#werkzeug.http.dump_header" title="werkzeug.http.dump_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump_header()</span></code></a> function.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> – a string with a list header.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_dict_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_dict_header</code><span class="sig-paren">(</span><em>value</em>, <em>cls=&lt;class 'dict'&gt;</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_dict_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict (or any other mapping object created from
the type with a dict like interface provided by the <cite>cls</cite> argument):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">parse_dict_header</span><span class="p">(</span><span class="s1">&#39;foo=&quot;is a fish&quot;, bar=&quot;as well&quot;&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">dict</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sorted</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<span class="go">[(&#39;bar&#39;, &#39;as well&#39;), (&#39;foo&#39;, &#39;is a fish&#39;)]</span>
</pre></div>
</div>
<p>If there is no value for a key it will be <cite>None</cite>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parse_dict_header</span><span class="p">(</span><span class="s1">&#39;key_without_value&#39;</span><span class="p">)</span>
<span class="go">{&#39;key_without_value&#39;: None}</span>
</pre></div>
</div>
<p>To create a header from the <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> again, use the
<a class="reference internal" href="#werkzeug.http.dump_header" title="werkzeug.http.dump_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump_header()</span></code></a> function.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.9: </span>Added support for <cite>cls</cite> argument.</p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>value</strong> – a string with a dict header.</li>
<li><strong>cls</strong> – callable to use for storage of parsed results.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">an instance of <cite>cls</cite></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_accept_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_accept_header</code><span class="sig-paren">(</span><em>value</em><span class="optional">[</span>, <em>class</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_accept_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses an HTTP Accept-* header.  This does not implement a complete
valid algorithm but one that supports at least value and quality
extraction.</p>
<p>Returns a new <code class="xref py py-class docutils literal notranslate"><span class="pre">Accept</span></code> object (basically a list of <code class="docutils literal notranslate"><span class="pre">(value,</span> <span class="pre">quality)</span></code>
tuples sorted by the quality with some additional accessor methods).</p>
<p>The second parameter can be a subclass of <code class="xref py py-class docutils literal notranslate"><span class="pre">Accept</span></code> that is created
with the parsed values and returned.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>value</strong> – the accept header string to be parsed.</li>
<li><strong>cls</strong> – the wrapper class for the return value (can be
<code class="xref py py-class docutils literal notranslate"><span class="pre">Accept</span></code> or a subclass thereof)</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">an instance of <cite>cls</cite>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_cache_control_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_cache_control_header</code><span class="sig-paren">(</span><em>value</em>, <em>on_update=None</em>, <em>cls=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_cache_control_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a cache control header.  The RFC differs between response and
request cache control, this method does not.  It’s your responsibility
to not use the wrong control statements.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.5: </span>The <cite>cls</cite> was added.  If not specified an immutable
<a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.RequestCacheControl" title="werkzeug.datastructures.RequestCacheControl"><code class="xref py py-class docutils literal notranslate"><span class="pre">RequestCacheControl</span></code></a> is returned.</p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>value</strong> – a cache control header to be parsed.</li>
<li><strong>on_update</strong> – an optional callable that is called every time a value
on the <code class="xref py py-class docutils literal notranslate"><span class="pre">CacheControl</span></code>
object is changed.</li>
<li><strong>cls</strong> – the class for the returned object.  By default
<a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.RequestCacheControl" title="werkzeug.datastructures.RequestCacheControl"><code class="xref py py-class docutils literal notranslate"><span class="pre">RequestCacheControl</span></code></a> is used.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a <cite>cls</cite> object.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_authorization_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_authorization_header</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_authorization_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse an HTTP basic/digest authorization header transmitted by the web
browser.  The return value is either <cite>None</cite> if the header was invalid or
not given, otherwise an <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.Authorization" title="werkzeug.datastructures.Authorization"><code class="xref py py-class docutils literal notranslate"><span class="pre">Authorization</span></code></a>
object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> – the authorization header to parse.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.Authorization" title="werkzeug.datastructures.Authorization"><code class="xref py py-class docutils literal notranslate"><span class="pre">Authorization</span></code></a> object or <cite>None</cite>.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_www_authenticate_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_www_authenticate_header</code><span class="sig-paren">(</span><em>value</em>, <em>on_update=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_www_authenticate_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse an HTTP WWW-Authenticate header into a
<a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.WWWAuthenticate" title="werkzeug.datastructures.WWWAuthenticate"><code class="xref py py-class docutils literal notranslate"><span class="pre">WWWAuthenticate</span></code></a> object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>value</strong> – a WWW-Authenticate header to parse.</li>
<li><strong>on_update</strong> – an optional callable that is called every time a value
on the <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.WWWAuthenticate" title="werkzeug.datastructures.WWWAuthenticate"><code class="xref py py-class docutils literal notranslate"><span class="pre">WWWAuthenticate</span></code></a>
object is changed.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.WWWAuthenticate" title="werkzeug.datastructures.WWWAuthenticate"><code class="xref py py-class docutils literal notranslate"><span class="pre">WWWAuthenticate</span></code></a> object.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_if_range_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_if_range_header</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_if_range_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses an if-range header which can be an etag or a date.  Returns
a <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.IfRange" title="werkzeug.datastructures.IfRange"><code class="xref py py-class docutils literal notranslate"><span class="pre">IfRange</span></code></a> object.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
</details></dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_range_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_range_header</code><span class="sig-paren">(</span><em>value</em>, <em>make_inclusive=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_range_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses a range header into a <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.Range" title="werkzeug.datastructures.Range"><code class="xref py py-class docutils literal notranslate"><span class="pre">Range</span></code></a>
object.  If the header is missing or malformed <cite>None</cite> is returned.
<cite>ranges</cite> is a list of <code class="docutils literal notranslate"><span class="pre">(start,</span> <span class="pre">stop)</span></code> tuples where the ranges are
non-inclusive.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
</details></dd></dl>

<dl class="function">
<dt id="werkzeug.http.parse_content_range_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_content_range_header</code><span class="sig-paren">(</span><em>value</em>, <em>on_update=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_content_range_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses a range header into a
<a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.ContentRange" title="werkzeug.datastructures.ContentRange"><code class="xref py py-class docutils literal notranslate"><span class="pre">ContentRange</span></code></a> object or <cite>None</cite> if
parsing is not possible.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>value</strong> – a content range header to be parsed.</li>
<li><strong>on_update</strong> – an optional callable that is called every time a value
on the <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.ContentRange" title="werkzeug.datastructures.ContentRange"><code class="xref py py-class docutils literal notranslate"><span class="pre">ContentRange</span></code></a>
object is changed.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="header-utilities">
<h2>Header Utilities<a class="headerlink" href="#header-utilities" title="Permalink to this headline">¶</a></h2>
<p>The following utilities operate on HTTP headers well but do not parse
them.  They are useful if you’re dealing with conditional responses or if
you want to proxy arbitrary requests but want to remove WSGI-unsupported
hop-by-hop headers.  Also there is a function to create HTTP header
strings from the parsed data.</p>
<dl class="function">
<dt id="werkzeug.http.is_entity_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">is_entity_header</code><span class="sig-paren">(</span><em>header</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.is_entity_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if a header is an entity header.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>header</strong> – the header to test.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><cite>True</cite> if it’s an entity header, <cite>False</cite> otherwise.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.is_hop_by_hop_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">is_hop_by_hop_header</code><span class="sig-paren">(</span><em>header</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.is_hop_by_hop_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if a header is an HTTP/1.1 “Hop-by-Hop” header.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>header</strong> – the header to test.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><cite>True</cite> if it’s an HTTP/1.1 “Hop-by-Hop” header, <cite>False</cite> otherwise.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.remove_entity_headers">
<code class="descclassname">werkzeug.http.</code><code class="descname">remove_entity_headers</code><span class="sig-paren">(</span><em>headers</em>, <em>allowed=('expires'</em>, <em>'content-location')</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.remove_entity_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove all entity headers from a list or <code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code> object.  This
operation works in-place.  <cite>Expires</cite> and <cite>Content-Location</cite> headers are
by default not removed.  The reason for this is <span class="target" id="index-2"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2616.html"><strong>RFC 2616</strong></a> section
10.3.5 which specifies some entity headers that should be sent.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.5: </span>added <cite>allowed</cite> parameter.</p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>headers</strong> – a list or <code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code> object.</li>
<li><strong>allowed</strong> – a list of headers that should still be allowed even though
they are entity headers.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.remove_hop_by_hop_headers">
<code class="descclassname">werkzeug.http.</code><code class="descname">remove_hop_by_hop_headers</code><span class="sig-paren">(</span><em>headers</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.remove_hop_by_hop_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove all HTTP/1.1 “Hop-by-Hop” headers from a list or
<code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code> object.  This operation works in-place.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>headers</strong> – a list or <code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code> object.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.is_byte_range_valid">
<code class="descclassname">werkzeug.http.</code><code class="descname">is_byte_range_valid</code><span class="sig-paren">(</span><em>start</em>, <em>stop</em>, <em>length</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.is_byte_range_valid" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if a given byte content range is valid for the given length.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
</details></dd></dl>

<dl class="function">
<dt id="werkzeug.http.quote_header_value">
<code class="descclassname">werkzeug.http.</code><code class="descname">quote_header_value</code><span class="sig-paren">(</span><em>value</em>, <em>extra_chars=''</em>, <em>allow_token=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.quote_header_value" title="Permalink to this definition">¶</a></dt>
<dd><p>Quote a header value if necessary.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>value</strong> – the value to quote.</li>
<li><strong>extra_chars</strong> – a list of extra characters to skip quoting.</li>
<li><strong>allow_token</strong> – if this is enabled token values are returned
unchanged.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.unquote_header_value">
<code class="descclassname">werkzeug.http.</code><code class="descname">unquote_header_value</code><span class="sig-paren">(</span><em>value</em>, <em>is_filename=False</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.unquote_header_value" title="Permalink to this definition">¶</a></dt>
<dd><p>Unquotes a header value.  (Reversal of <a class="reference internal" href="#werkzeug.http.quote_header_value" title="werkzeug.http.quote_header_value"><code class="xref py py-func docutils literal notranslate"><span class="pre">quote_header_value()</span></code></a>).
This does not use the real unquoting but what browsers are actually
using for quoting.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> – the header value to unquote.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.dump_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">dump_header</code><span class="sig-paren">(</span><em>iterable</em>, <em>allow_token=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.dump_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Dump an HTTP header again.  This is the reversal of
<a class="reference internal" href="#werkzeug.http.parse_list_header" title="werkzeug.http.parse_list_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_list_header()</span></code></a>, <a class="reference internal" href="#werkzeug.http.parse_set_header" title="werkzeug.http.parse_set_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_set_header()</span></code></a> and
<a class="reference internal" href="#werkzeug.http.parse_dict_header" title="werkzeug.http.parse_dict_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_dict_header()</span></code></a>.  This also quotes strings that include an
equals sign unless you pass it as dict of key, value pairs.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">dump_header</span><span class="p">({</span><span class="s1">&#39;foo&#39;</span><span class="p">:</span> <span class="s1">&#39;bar baz&#39;</span><span class="p">})</span>
<span class="go">&#39;foo=&quot;bar baz&quot;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dump_header</span><span class="p">((</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="s1">&#39;bar baz&#39;</span><span class="p">))</span>
<span class="go">&#39;foo, &quot;bar baz&quot;&#39;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>iterable</strong> – the iterable or dict of values to quote.</li>
<li><strong>allow_token</strong> – if set to <cite>False</cite> tokens as values are disallowed.
See <a class="reference internal" href="#werkzeug.http.quote_header_value" title="werkzeug.http.quote_header_value"><code class="xref py py-func docutils literal notranslate"><span class="pre">quote_header_value()</span></code></a> for more details.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="cookies">
<h2>Cookies<a class="headerlink" href="#cookies" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="werkzeug.http.parse_cookie">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_cookie</code><span class="sig-paren">(</span><em>header</em>, <em>charset='utf-8'</em>, <em>errors='replace'</em>, <em>cls=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_cookie" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a cookie from a string or WSGI environ.</p>
<p>The same key can be provided multiple times, the values are stored
in-order. The default <code class="xref py py-class docutils literal notranslate"><span class="pre">MultiDict</span></code> will have the first value
first, and all values can be retrieved with
<code class="xref py py-meth docutils literal notranslate"><span class="pre">MultiDict.getlist()</span></code>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>header</strong> – The cookie header as a string, or a WSGI environ dict
with a <code class="docutils literal notranslate"><span class="pre">HTTP_COOKIE</span></code> key.</li>
<li><strong>charset</strong> – The charset for the cookie values.</li>
<li><strong>errors</strong> – The error behavior for the charset decoding.</li>
<li><strong>cls</strong> – A dict-like class to store the parsed cookies in.
Defaults to <code class="xref py py-class docutils literal notranslate"><span class="pre">MultiDict</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.0.0: </span>Returns a <code class="xref py py-class docutils literal notranslate"><span class="pre">MultiDict</span></code> instead of a
<code class="docutils literal notranslate"><span class="pre">TypeConversionDict</span></code>.</p>
</div>
<details class="changelog">
<summary>Changelog</summary><div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.5: </span>Returns a <code class="xref py py-class docutils literal notranslate"><span class="pre">TypeConversionDict</span></code> instead of a regular dict.
The <code class="docutils literal notranslate"><span class="pre">cls</span></code> parameter was added.</p>
</div>
</details></dd></dl>

<dl class="function">
<dt id="werkzeug.http.dump_cookie">
<code class="descclassname">werkzeug.http.</code><code class="descname">dump_cookie</code><span class="sig-paren">(</span><em>key</em>, <em>value=''</em>, <em>max_age=None</em>, <em>expires=None</em>, <em>path='/'</em>, <em>domain=None</em>, <em>secure=False</em>, <em>httponly=False</em>, <em>charset='utf-8'</em>, <em>sync_expires=True</em>, <em>max_size=4093</em>, <em>samesite=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.dump_cookie" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a new Set-Cookie header without the <code class="docutils literal notranslate"><span class="pre">Set-Cookie</span></code> prefix
The parameters are the same as in the cookie Morsel object in the
Python standard library but it accepts unicode data, too.</p>
<p>On Python 3 the return value of this function will be a unicode
string, on Python 2 it will be a native string.  In both cases the
return value is usually restricted to ascii as the vast majority of
values are properly escaped, but that is no guarantee.  If a unicode
string is returned it’s tunneled through latin1 as required by
PEP 3333.</p>
<p>The return value is not ASCII safe if the key contains unicode
characters.  This is technically against the specification but
happens in the wild.  It’s strongly recommended to not use
non-ASCII values for the keys.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>max_age</strong> – should be a number of seconds, or <cite>None</cite> (default) if
the cookie should last only as long as the client’s
browser session.  Additionally <cite>timedelta</cite> objects
are accepted, too.</li>
<li><strong>expires</strong> – should be a <cite>datetime</cite> object or unix timestamp.</li>
<li><strong>path</strong> – limits the cookie to a given path, per default it will
span the whole domain.</li>
<li><strong>domain</strong> – Use this if you want to set a cross-domain cookie. For
example, <code class="docutils literal notranslate"><span class="pre">domain=&quot;.example.com&quot;</span></code> will set a cookie
that is readable by the domain <code class="docutils literal notranslate"><span class="pre">www.example.com</span></code>,
<code class="docutils literal notranslate"><span class="pre">foo.example.com</span></code> etc. Otherwise, a cookie will only
be readable by the domain that set it.</li>
<li><strong>secure</strong> – The cookie will only be available via HTTPS</li>
<li><strong>httponly</strong> – disallow JavaScript to access the cookie.  This is an
extension to the cookie standard and probably not
supported by all browsers.</li>
<li><strong>charset</strong> – the encoding for unicode values.</li>
<li><strong>sync_expires</strong> – automatically set expires if max_age is defined
but expires not.</li>
<li><strong>max_size</strong> – Warn if the final header value exceeds this size. The
default, 4093, should be safely <a class="reference external" href="http://browsercookielimits.squawky.net/">supported by most browsers</a>. Set to 0 to disable this check.</li>
<li><strong>samesite</strong> – Limits the scope of the cookie such that it will
only be attached to requests if those requests are same-site.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.0.0: </span>The string <code class="docutils literal notranslate"><span class="pre">'None'</span></code> is accepted for <code class="docutils literal notranslate"><span class="pre">samesite</span></code>.</p>
</div>
</dd></dl>

</div>
<div class="section" id="conditional-response-helpers">
<h2>Conditional Response Helpers<a class="headerlink" href="#conditional-response-helpers" title="Permalink to this headline">¶</a></h2>
<p>For conditional responses the following functions might be useful:</p>
<dl class="function">
<dt id="werkzeug.http.parse_etags">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_etags</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_etags" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse an etag header.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> – the tag header to parse</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">an <a class="reference internal" href="../datastructures/index.html#werkzeug.datastructures.ETags" title="werkzeug.datastructures.ETags"><code class="xref py py-class docutils literal notranslate"><span class="pre">ETags</span></code></a> object.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.quote_etag">
<code class="descclassname">werkzeug.http.</code><code class="descname">quote_etag</code><span class="sig-paren">(</span><em>etag</em>, <em>weak=False</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.quote_etag" title="Permalink to this definition">¶</a></dt>
<dd><p>Quote an etag.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>etag</strong> – the etag to quote.</li>
<li><strong>weak</strong> – set to <cite>True</cite> to tag it “weak”.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.unquote_etag">
<code class="descclassname">werkzeug.http.</code><code class="descname">unquote_etag</code><span class="sig-paren">(</span><em>etag</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.unquote_etag" title="Permalink to this definition">¶</a></dt>
<dd><p>Unquote a single etag:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">unquote_etag</span><span class="p">(</span><span class="s1">&#39;W/&quot;bar&quot;&#39;</span><span class="p">)</span>
<span class="go">(&#39;bar&#39;, True)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">unquote_etag</span><span class="p">(</span><span class="s1">&#39;&quot;bar&quot;&#39;</span><span class="p">)</span>
<span class="go">(&#39;bar&#39;, False)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>etag</strong> – the etag identifier to unquote.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a <code class="docutils literal notranslate"><span class="pre">(etag,</span> <span class="pre">weak)</span></code> tuple.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.generate_etag">
<code class="descclassname">werkzeug.http.</code><code class="descname">generate_etag</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.generate_etag" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate an etag for some data.</p>
</dd></dl>

<dl class="function">
<dt id="werkzeug.http.is_resource_modified">
<code class="descclassname">werkzeug.http.</code><code class="descname">is_resource_modified</code><span class="sig-paren">(</span><em>environ</em>, <em>etag=None</em>, <em>data=None</em>, <em>last_modified=None</em>, <em>ignore_if_range=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.is_resource_modified" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience method for conditional requests.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>environ</strong> – the WSGI environment of the request to be checked.</li>
<li><strong>etag</strong> – the etag for the response for comparison.</li>
<li><strong>data</strong> – or alternatively the data of the response to automatically
generate an etag using <a class="reference internal" href="#werkzeug.http.generate_etag" title="werkzeug.http.generate_etag"><code class="xref py py-func docutils literal notranslate"><span class="pre">generate_etag()</span></code></a>.</li>
<li><strong>last_modified</strong> – an optional date of the last modification.</li>
<li><strong>ignore_if_range</strong> – If <cite>False</cite>, <cite>If-Range</cite> header will be taken into
account.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><cite>True</cite> if the resource was modified, otherwise <cite>False</cite>.</p>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.0.0: </span>The check is run for methods other than <code class="docutils literal notranslate"><span class="pre">GET</span></code> and <code class="docutils literal notranslate"><span class="pre">HEAD</span></code>.</p>
</div>
</dd></dl>

</div>
<div class="section" id="constants">
<h2>Constants<a class="headerlink" href="#constants" title="Permalink to this headline">¶</a></h2>
<dl class="data">
<dt id="werkzeug.http.HTTP_STATUS_CODES">
<code class="descclassname">werkzeug.http.</code><code class="descname">HTTP_STATUS_CODES</code><a class="headerlink" href="#werkzeug.http.HTTP_STATUS_CODES" title="Permalink to this definition">¶</a></dt>
<dd><p>A dict of status code -&gt; default status message pairs.  This is used
by the wrappers and other places where an integer status code is expanded
to a string throughout Werkzeug.</p>
</dd></dl>

</div>
<div class="section" id="module-werkzeug.formparser">
<span id="form-data-parsing"></span><h2>Form Data Parsing<a class="headerlink" href="#module-werkzeug.formparser" title="Permalink to this headline">¶</a></h2>
<p>Werkzeug provides the form parsing functions separately from the request
object so that you can access form data from a plain WSGI environment.</p>
<p>The following formats are currently supported by the form data parser:</p>
<ul class="simple">
<li><cite>application/x-www-form-urlencoded</cite></li>
<li><cite>multipart/form-data</cite></li>
</ul>
<p>Nested multipart is not currently supported (Werkzeug 0.9), but it isn’t used
by any of the modern web browsers.</p>
<p>Usage example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cStringIO</span> <span class="k">import</span> <span class="n">StringIO</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;--foo</span><span class="se">\r\n</span><span class="s1">Content-Disposition: form-data; name=&quot;test&quot;</span><span class="se">\r\n</span><span class="s1">&#39;</span> \
<span class="gp">... </span><span class="s1">&#39;</span><span class="se">\r\n</span><span class="s1">Hello World!</span><span class="se">\r\n</span><span class="s1">--foo--&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">environ</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;wsgi.input&#39;</span><span class="p">:</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="s1">&#39;CONTENT_LENGTH&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)),</span>
<span class="gp">... </span>           <span class="s1">&#39;CONTENT_TYPE&#39;</span><span class="p">:</span> <span class="s1">&#39;multipart/form-data; boundary=foo&#39;</span><span class="p">,</span>
<span class="gp">... </span>           <span class="s1">&#39;REQUEST_METHOD&#39;</span><span class="p">:</span> <span class="s1">&#39;POST&#39;</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">stream</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="n">files</span> <span class="o">=</span> <span class="n">parse_form_data</span><span class="p">(</span><span class="n">environ</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">stream</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="go">&#39;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">form</span><span class="p">[</span><span class="s1">&#39;test&#39;</span><span class="p">]</span>
<span class="go">u&#39;Hello World!&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="ow">not</span> <span class="n">files</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Normally the WSGI environment is provided by the WSGI gateway with the
incoming data as part of it.  If you want to generate such fake-WSGI
environments for unittesting you might want to use the
<code class="xref py py-func docutils literal notranslate"><span class="pre">create_environ()</span></code> function or the <code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironBuilder</span></code> instead.</p>
<dl class="class">
<dt id="werkzeug.formparser.FormDataParser">
<em class="property">class </em><code class="descclassname">werkzeug.formparser.</code><code class="descname">FormDataParser</code><span class="sig-paren">(</span><em>stream_factory=None</em>, <em>charset='utf-8'</em>, <em>errors='replace'</em>, <em>max_form_memory_size=None</em>, <em>max_content_length=None</em>, <em>cls=None</em>, <em>silent=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.formparser.FormDataParser" title="Permalink to this definition">¶</a></dt>
<dd><p>This class implements parsing of form data for Werkzeug.  By itself
it can parse multipart and url encoded form data.  It can be subclassed
and extended but for most mimetypes it is a better idea to use the
untouched stream and expose it as separate attributes on a request
object.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.8.</span></p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>stream_factory</strong> – An optional callable that returns a new read and
writeable file descriptor.  This callable works
the same as <code class="xref py py-meth docutils literal notranslate"><span class="pre">_get_file_stream()</span></code>.</li>
<li><strong>charset</strong> – The character set for URL and url encoded form data.</li>
<li><strong>errors</strong> – The encoding error behavior.</li>
<li><strong>max_form_memory_size</strong> – the maximum number of bytes to be accepted for
in-memory stored form data.  If the data
exceeds the value specified an
<code class="xref py py-exc docutils literal notranslate"><span class="pre">RequestEntityTooLarge</span></code>
exception is raised.</li>
<li><strong>max_content_length</strong> – If this is provided and the transmitted data
is longer than this value an
<code class="xref py py-exc docutils literal notranslate"><span class="pre">RequestEntityTooLarge</span></code>
exception is raised.</li>
<li><strong>cls</strong> – an optional dict class to use.  If this is not specified
or <cite>None</cite> the default <code class="xref py py-class docutils literal notranslate"><span class="pre">MultiDict</span></code> is used.</li>
<li><strong>silent</strong> – If set to False parsing errors will not be caught.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.formparser.parse_form_data">
<code class="descclassname">werkzeug.formparser.</code><code class="descname">parse_form_data</code><span class="sig-paren">(</span><em>environ</em>, <em>stream_factory=None</em>, <em>charset='utf-8'</em>, <em>errors='replace'</em>, <em>max_form_memory_size=None</em>, <em>max_content_length=None</em>, <em>cls=None</em>, <em>silent=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.formparser.parse_form_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse the form data in the environ and return it as tuple in the form
<code class="docutils literal notranslate"><span class="pre">(stream,</span> <span class="pre">form,</span> <span class="pre">files)</span></code>.  You should only call this method if the
transport method is <cite>POST</cite>, <cite>PUT</cite>, or <cite>PATCH</cite>.</p>
<p>If the mimetype of the data transmitted is <cite>multipart/form-data</cite> the
files multidict will be filled with <cite>FileStorage</cite> objects.  If the
mimetype is unknown the input stream is wrapped and returned as first
argument, else the stream is empty.</p>
<p>This is a shortcut for the common usage of <a class="reference internal" href="#werkzeug.formparser.FormDataParser" title="werkzeug.formparser.FormDataParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">FormDataParser</span></code></a>.</p>
<p>Have a look at <a class="reference internal" href="../request_data/index.html#dealing-with-request-data"><span class="std std-ref">Dealing with Request Data</span></a> for more details.</p>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.1: </span>The optional <cite>silent</cite> flag was added.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5: </span>The <cite>max_form_memory_size</cite>, <cite>max_content_length</cite> and
<cite>cls</cite> parameters were added.</p>
</div>
</details><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>environ</strong> – the WSGI environment to be used for parsing.</li>
<li><strong>stream_factory</strong> – An optional callable that returns a new read and
writeable file descriptor.  This callable works
the same as <code class="xref py py-meth docutils literal notranslate"><span class="pre">_get_file_stream()</span></code>.</li>
<li><strong>charset</strong> – The character set for URL and url encoded form data.</li>
<li><strong>errors</strong> – The encoding error behavior.</li>
<li><strong>max_form_memory_size</strong> – the maximum number of bytes to be accepted for
in-memory stored form data.  If the data
exceeds the value specified an
<code class="xref py py-exc docutils literal notranslate"><span class="pre">RequestEntityTooLarge</span></code>
exception is raised.</li>
<li><strong>max_content_length</strong> – If this is provided and the transmitted data
is longer than this value an
<code class="xref py py-exc docutils literal notranslate"><span class="pre">RequestEntityTooLarge</span></code>
exception is raised.</li>
<li><strong>cls</strong> – an optional dict class to use.  If this is not specified
or <cite>None</cite> the default <code class="xref py py-class docutils literal notranslate"><span class="pre">MultiDict</span></code> is used.</li>
<li><strong>silent</strong> – If set to False parsing errors will not be caught.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A tuple in the form <code class="docutils literal notranslate"><span class="pre">(stream,</span> <span class="pre">form,</span> <span class="pre">files)</span></code>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="werkzeug.formparser.parse_multipart_headers">
<code class="descclassname">werkzeug.formparser.</code><code class="descname">parse_multipart_headers</code><span class="sig-paren">(</span><em>iterable</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.formparser.parse_multipart_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses multipart headers from an iterable that yields lines (including
the trailing newline symbol).  The iterable has to be newline terminated.</p>
<p>The iterable will stop at the line where the headers ended so it can be
further consumed.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>iterable</strong> – iterable of strings that are newline terminated</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
  <span id="sidebar-top"></span>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  
    
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/werkzeug.png" alt="Logo"/>
            </a></p>
  

  <h3>Contents</h3>
  <ul>
<li><a class="reference internal" href="#">HTTP Utilities</a><ul>
<li><a class="reference internal" href="#date-functions">Date Functions</a></li>
<li><a class="reference internal" href="#header-parsing">Header Parsing</a></li>
<li><a class="reference internal" href="#header-utilities">Header Utilities</a></li>
<li><a class="reference internal" href="#cookies">Cookies</a></li>
<li><a class="reference internal" href="#conditional-response-helpers">Conditional Response Helpers</a></li>
<li><a class="reference internal" href="#constants">Constants</a></li>
<li><a class="reference internal" href="#module-werkzeug.formparser">Form Data Parsing</a></li>
</ul>
</li>
</ul>
<h3>Navigation</h3>
<ul>
  <li><a href="../index.html">Overview</a>
    <ul>
          <li>Previous: <a href="../filesystem/index.html" title="previous chapter">Filesystem Utilities</a>
          <li>Next: <a href="../datastructures/index.html" title="next chapter">Data Structures</a>
    </ul>
  </li>
</ul>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://werkzeug.palletsprojects.com/en/1.0.x/search/" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
  
    <div class="footer" role="contentinfo">
        &#169; Copyright 2007 Pallets.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
    </div>
    <script>
      if (typeof READTHEDOCS_DATA !== 'undefined') {
        if (!READTHEDOCS_DATA.features) {
          READTHEDOCS_DATA.features = {};
        }
        READTHEDOCS_DATA.features.docsearch_disabled = true;
      }
    </script>

  </body>

<!-- Mirrored from werkzeug.palletsprojects.com/en/1.0.x/http/ by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 15 Sep 2020 06:37:09 GMT -->
</html>